﻿
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WebAPIUI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UpLoadController : ControllerBase
    {
        public UpLoadController(IWebHostEnvironment web)
        {
            Web = web;
        }

        public IWebHostEnvironment Web { get; }

        [HttpPost]
        public IActionResult UpFile(IFormFile file)
        {
            string m = DateTime.Now.ToString("yyyyMMddHHmmss");
            string path = Web.WebRootPath + @"\pic\" + m + file.FileName;
            using (FileStream fs = System.IO.File.Create(path))
            {
                file.CopyTo(fs);
                fs.Close();
            }
            return Ok("/pic/" + m + file.FileName);
        }
    }
}
